package com.ruoyi.web.controller.purchase;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.pojo.PurchaseOrderMaterial;
import com.ruoyi.purchase.service.PurchaseOrderMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购订单物料清单Controller
 *
 * @author ruoyi
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/purchase/orderMaterial")
public class PurchaseOrderMaterialController extends BaseController
{
    @Autowired
    private PurchaseOrderMaterialService purchaseOrderMaterialService;

    /**
     * 查询采购订单物料清单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PurchaseOrderMaterial purchaseOrderMaterial)
    {
        startPage();
        List<PurchaseOrderMaterial> list = purchaseOrderMaterialService.selectPurchaseOrderMaterialList(purchaseOrderMaterial);
        return getDataTable(list);
    }

    /**
     * 导出采购订单物料清单列表
     */
    @Log(title = "采购订单物料清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseOrderMaterial purchaseOrderMaterial)
    {
        List<PurchaseOrderMaterial> list = purchaseOrderMaterialService.selectPurchaseOrderMaterialList(purchaseOrderMaterial);
        ExcelUtil<PurchaseOrderMaterial> util = new ExcelUtil<PurchaseOrderMaterial>(PurchaseOrderMaterial.class);
        util.exportExcel(response, list, "采购订单物料清单数据");
    }

    /**
     * 获取采购订单物料清单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(purchaseOrderMaterialService.selectPurchaseOrderMaterialById(id));
    }

    /**
     * 新增采购订单物料清单
     */
    @Log(title = "采购订单物料清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseOrderMaterial purchaseOrderMaterial)
    {
        return toAjax(purchaseOrderMaterialService.insertPurchaseOrderMaterial(purchaseOrderMaterial));
    }

    /**
     * 修改采购订单物料清单
     */
    @Log(title = "采购订单物料清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseOrderMaterial purchaseOrderMaterial)
    {
        return toAjax(purchaseOrderMaterialService.updatePurchaseOrderMaterial(purchaseOrderMaterial));
    }

    /**
     * 删除采购订单物料清单
     */
    @Log(title = "采购订单物料清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(purchaseOrderMaterialService.deletePurchaseOrderMaterialByIds(ids));
    }
}
